package com.lly.tboc

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual
import io.kotest.matchers.ints.shouldBeInRange
import io.kotest.matchers.ints.shouldBeLessThanOrEqual
import io.kotest.matchers.shouldBe
import io.mockk.clearAllMocks
import io.mockk.coEvery
import io.mockk.mockk


class ZhouYiTest : StringSpec({
    val guaDao = mockk<com.lly.tboc.zhouyi.db.GuaDao>()
    val yaoDao = mockk<com.lly.tboc.zhouyi.db.YaoDao>()
    afterTest { (_, _) ->
        clearAllMocks()
    }
    "解析周易数据" {
        val gua = com.lly.tboc.zhouyi.vo.Gua(
            id = 1, name = "乾", outer = "乾", inner = "乾",
            ci = "元亨利贞", tuan = "大哉乾元 万物兹始 乃统天",
            xiang = "天行健，君子以自强不息", wu = "等待"
        )
        com.lly.tboc.zhouyi.vo.Gua.parse(gua.toDataForString().apply { println(this) }) shouldBe gua
    }
    "随机一卦，卦id在1～64之间" {
        coEvery { guaDao.get(any<Int>()) } returns null
        repeat(100) {
            val randomGua = com.lly.tboc.zhouyi.everyday.EveryDayOneGua.randomGua()
            randomGua shouldBeGreaterThanOrEqual 0
            randomGua shouldBeLessThanOrEqual 64
        }

    }
    "随机乾卦一爻，爻id在1～7之间" {
        coEvery { yaoDao.get(any(), any()) } returns null
        repeat(100) {
            com.lly.tboc.zhouyi.everyday.EveryDayOneGua.randomYao(1) shouldBeInRange IntRange(1, 7)
        }
    }
    "随机坤卦一爻，爻id在1～7之间" {
        coEvery { yaoDao.get(any(), any()) } returns null
        repeat(100) {
            com.lly.tboc.zhouyi.everyday.EveryDayOneGua.randomYao(1) shouldBeInRange IntRange(1, 7)
        }
    }
    "随机非乾、坤卦一爻，爻id在1～6之间" {
        coEvery { yaoDao.get(any(), any()) } returns null
        repeat(100) {
            com.lly.tboc.zhouyi.everyday.EveryDayOneGua.randomYao(3) shouldBeInRange IntRange(1, 6)
        }
    }

})
